/**
 * 
 */
package com.ms.service.module.processer;

import java.lang.reflect.Method;

import com.xpec.c4.game.datamanager.BaseDataInfo;
import com.xpec.c4.game.datamanager.agent.PlayerData;
import com.xpec.c4.game.login.async2.DoAfterLoadPlayerAsync;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.service.common.BaseMessageAction;

/**
 * @author TW15010
 *
 */
public class DMDoSeatGetPlayerAsync extends DoAfterLoadPlayerAsync {
	/**
	 * class instance of callback
	 */
	private BaseMessageAction baseaction;

	/**
	 * callback
	 */
	private Method cbMethod;

	/**
	 * 自訂參數
	 */
	private Object[] params;

	/**
	 * @param baseaction
	 *            載入角色資料後要執行的 callback 所在的物件
	 * @param callbackMethodName
	 *            載入角色資料後要執行的 callback 名稱
	 * @param params
	 *            要傳入 callback 的自訂參數
	 */
	public void initial2(BaseMessageAction baseaction, String callbackMethodName, Object... params) {
		this.baseaction = baseaction;

		cbMethod = GameUtility.getMethod(baseaction, callbackMethodName, new Class[] { BaseDataInfo.class,
				Object[].class });

		this.params = params;
	}

	@Override
	public void execute() throws Exception {
		super.execute();

		PlayerData data = new PlayerData();
		data.setPlayer(getLoadPlayer());
		data.setResultCode(getResultCode());

		cbMethod.setAccessible(true);
		cbMethod.invoke(baseaction, data, params);
	}
}
